<template>
  <el-table
    v-loading="loading"
    border
    :data="newTableData"
    style="margin-top: 14px"
    :header-cell-style="{ color: '#646464' }"
    type="index"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
  >
    <el-table-column
      v-if="tableIndex === 0"
      label="#"
      type="index"
    />
    <el-table-column
      v-for="item in newTableEle"
      :key="item.prop"
      :prop="item.prop"
      :label="item.name"
    >
      <template slot-scope="{row}">
        <slot v-if="item.template" :name="item.prop" :row="row" />
        <slot v-else>{{ row[item.prop] }}</slot>
      </template>
    </el-table-column>
    <el-table-column label="操作" align="center">
      <template #default="{ row }">
        <el-button
          type="primary"
          icon="el-icon-edit"
          circle
          @click="handlerEdit('edit', row.id)"
        />
        <el-button
          type="danger"
          icon="el-icon-delete"
          circle
          @click="handlerDel(row.id)"
        />

      </template>
    </el-table-column>
  </el-table>
</template>

<script>
// import dayjs from 'dayjs'
export default {
  name: 'MyTable',
  props: {
    tableData: {
      type: Array,
      default: () => []
    },
    tableEle: {
      type: Array,
      default: () => []
    },
    tableIndex: {
      type: Number,
      default: 0
    },
    loading: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    newTableEle() {
      // return this.tableEle.filter((item) => item.type)
      return this.tableEle.filter((item) => item.isckecked)
    },
    newTableData() {
      return this.tableData.map(item => {
        // if (item.status === 0) item.status = '待审核'
        // if (item.status === 1) item.status = '草稿箱'
        // if (item.status === 2) item.status = '已发布'
        // if (item.status === 3) item.status = '以删除'
        // item.pic = this.$ImgUrl + item.pic
        // item.ishot = item.ishot === 1
        // item.istop = item.istop === 1
        // item.create_date = dayjs(item.create_date).format('YYYY-MM-DD')
        return item
      })
    }
  },
  methods: {
    handlerDel(id) {
      this.$emit('del', id)
    },
    handlerEdit(type, id) {
      this.$emit('edit', id)
    },
    update(val) {
      this.$emit('update', val)
    }
  }
}
</script>

<style>
</style>
